/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lu.med.praxiswahl.wahlumed.dao.beans;


import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import lu.med.praxiswahl.wahlumed.dao.beans.daointerface.CodeRatesDAOInt;
import lu.med.praxiswahl.wahlumed.model.beans.CodeRatesTBL;

/**
 * 
 * @author Patrick kendzo Email: pkendzo@msn.com
 */

@Stateless
public class CodeRatesDAO implements CodeRatesDAOInt
{

    @PersistenceContext(unitName = "gynaekomedic-ejbPU")
    private EntityManager em = null;

    public CodeRatesDAO()
    {

    }

    @Override
    public void delete(Long todo)
    {
	CodeRatesTBL coRates = em.find(CodeRatesTBL.class, todo);
	em.remove(coRates);
	em.flush();

    }

    @SuppressWarnings("unchecked")
    @Override
    public List<CodeRatesTBL> findAvailableCodeRates()
    {
	try
	{

	    List<CodeRatesTBL> resultList = (List<CodeRatesTBL>) em
		    .createQuery("select co from CodeRatesTBL co order by prioritaet desc")
		    .getResultList();
	    return resultList;
	}
	catch (Exception e)
	{
	    throw new RuntimeException("CodeRatesTBL is empty", e);
	}
    }

    @Override
    public void persist(CodeRatesTBL todo)
    {
	em.persist(todo);
	em.flush();

    }

    @Override
    public void update(CodeRatesTBL todo)
    {
	em.merge(todo);
	em.flush();

    }

    @Override
    public CodeRatesTBL retrieveCodeRateByID(Long id)
    {
	return (CodeRatesTBL) em.find(CodeRatesTBL.class, id);
    }

}
